<template>
	<view style="background-color: #F8F8F8;padding-bottom: 50rpx;height: 100vh;">

		<view class="topmxx ">
			<view class="dis_f aic ">
				<image :src="userInfo.head_img || '../../static/images/user.png'" mode="aspectFill" class="userimg"
					@click="biaji">
				</image>
				<view class="cf ml20" v-if="userInfo.nickname"
					@click="jump('/pagesA/my_user_information/my_user_information')">
					<view class="dis_f aic ">
						<text class="fs34">{{userInfo.nickname }}</text>
						<view class="fs26 mt10 shangj ml20">{{userInfo.vip_cn}}</view>
					</view>
					<view class="dis_f aic">
						<view class="fs26 mt10 shangj" v-if="userInfo.t_userId">{{userInfo.parent_user}}</view>
					</view>
					<!-- <view class="fs26 mt10">{{userInfo.mobile}}</view> -->
				</view>
				<view class="cf ml20" v-else @click="showxieyi = true">
					<view class="dis_f aic">
						<text class="fs34"> 未登录</text>
						<text class="iconfont icon-bianji"></text>
						<image src="../../static/images/mengyou.png" mode="aspectFill" class="mengyimg ml20"
							v-if="userInfo.is_member == 2"></image>
					</view>
					<view class="fs26 mt10">请点击登录</view>

				</view>
			</view>
			<view class="dis_f aic jusa mt20">
				<view class="dis_f aic fdc cf" @click="jump('/pagesA/my_user_balance/my_user_balance')">
					<view class="fs30">
						{{userInfo.balance || 0}}
					</view>
					<view class="fs26">
						余额
					</view>
				</view>
				<view class="fs40 cf">
					|
				</view>
				<view class="dis_f aic fdc cf" @click="jump('/pagesA/my_user_integral/my_user_integral')">
					<view class="fs30">
						{{userInfo.integral || 0}}
					</view>
					<view class="fs26">
						积分
					</view>
				</view>
			</view>
		</view>

		<view class="yue dis_f aic juc" @click="jump('/pagesA/my_user_Recharge/my_user_Recharge')">
			余额充值
		</view>
		<view class="dis_f  juc mt20">
			<view class="fs26 cred " @click="vipjuip" v-if="userInfo.vip_goods_id">
				升级为VIP会员
			</view>
		</view>
		<view class=" dis_f aic jub mian" @click="jump('/pagesA/my_user_orderlist/my_user_orderlist?status='+0)">
			<view class="fs28">
				全部订单
			</view>
			<text class="icon-jiantou iconfont"></text>
		</view>
		<view class="mian dis_f aic jub ">
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_orderlist/my_user_orderlist?status='+1)">
				<text class="icon-daifahuo iconfont"></text>
				<view class="fs28 mt10">待付款</view>
			</view>

			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_orderlist/my_user_orderlist?status='+2)">
				<text class="icon-store iconfont"></text>
				<view class="fs28 mt10">待取货</view>
			</view>
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_orderlist/my_user_orderlist?status='+3)">
				<text class="icon-yiwancheng2 iconfont"></text>
				<view class="fs28 mt10">已完成</view>
			</view>
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_orderlist/my_user_orderlist?status='+0)">
				<text class="icon-a-quanbu2 iconfont"></text>
				<view class="fs28 mt10">全部</view>
			</view>
		</view>

		<view class="mian dis_f aic jub ">
			<view class="dis_f aic fdc" @click="jump('/pagesA/in_promotion/in_promotion')">
				<text class="icon-tuiguangma iconfont"></text>
				<view class="fs28 mt10">我的推广</view>
			</view>

			<view class="dis_f aic fdc" @click="jump('/pagesA/in_text/in_text?type='+0)">
				<text class="icon-shiyongshuoming iconfont"></text>
				<view class="fs28 mt10">使用说明</view>
			</view>

			<button type="default" open-type="contact" style="    height: 103rpx; line-height: 1.13;">
				<view class="dis_f aic fdc">
					<text class="icon-kefu iconfont"></text>
					<view class="fs28 mt10">联系客服</view>
				</view>
			</button>

			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_team/my_user_team')">
				<text class="icon-tuandui iconfont"></text>
				<view class="fs28 mt10">我的团队</view>
			</view>
		</view>
		<view class="mian dis_f aic jub ">
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_balance/my_user_balance')">
				<text class="icon-xiaofeimingxidan iconfont"></text>
				<view class="fs28 mt10">余额明细</view>
			</view>

			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_integral/my_user_integral')">
				<text class="icon-jifen iconfont"></text>
				<view class="fs28 mt10">积分明细</view>
			</view>
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_Tips/my_user_Tips')">
				<text class="icon-tixian iconfont"></text>
				<view class="fs28 mt10">余额提现</view>
			</view>
			<view class="dis_f aic fdc" @click="jump('/pagesA/my_user_information/my_user_information')">
				<text class="icon-ziliao iconfont "></text>
				<view class="fs28 mt10">个人资料</view>
			</view>
		</view>
		<view @click="close()" class="maxxback" v-if="showxieyi">
		</view>
		<view class="puop" v-if="showxieyi">
			<image src="https://lgy.59w.net//static/applet/login.png" mode="aspectFill" class="baoqu">
			</image>
			<view class="login_box">
				<view class="fs34">
					欢迎来到
				</view>
				<view style="font-size: 66rpx;color: #FE375D;">
					九淘
				</view>


				<button class="wxbtn mt50 cf dis_f aic juc" @click="getUserInfo" open-type="getPhoneNumber"
					@getphonenumber="onGetPhoneNumber">
					授权登录
				</button>
				<!-- open-type="getPhoneNumber"
					@getphonenumber="onGetPhoneNumber"  -->
				<view class="mt40 fs26 cac dis_f aic">
					<radio color="#0aa0ff" value="" :checked="checked" @click="dianji" style='transform: scale(0.6)' />
					<view class="fs24 dis_f aic" style="margin: 0rpx 0 0 -5rpx;">
						<view class="">
							已阅读并同意
						</view>

						<view @click="yopngh(2)">《入驻协议》和
						</view>
						<view @click="yopngh(1)">《用户隐私协议》
						</view>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				showxieyi: false,
				checked: false,
				userInfo: '',
				code: '',
				token: ""
			}
		},
		onShow() {
			console.log(this.api)
			this.token = uni.getStorageSync('token')
			if (this.token == '') {
				this.showxieyi = true
			} else {
				this.getuser()
			}
		},
		onLoad(option) {
			console.log(option.invite_id)
			if(option.invite_id) {
				uni.setStorageSync('invite_id', option.invite_id)
			}
		},
		//发送给朋友
		onShareAppMessage(res) {
			// 此处的distSource为分享者的部分信息，需要传递给其他人
			return {
				title: '九淘',
				type: 0,
				path: '/pages/my/my?invite_id=' + this.userInfo.id,
		
			}
		},
		//分享到朋友圈
		onShareTimeline(res) {
			return {
				title: '九淘',
				type: 0,
				path: '/pages/my/my?invite_id=' + this.userInfo.id,
			}
			// }
		},
		methods: {
			vipjuip() {
				uni.navigateTo({
					url: '/pagesA/in_details/in_details?id=' + this.userInfo.vip_goods_id
				})
			},
			renew() {
				const updateManager = wx.getUpdateManager()
				updateManager.onCheckForUpdate(function(res) {
					// 请求完新版本信息的回调
					if (res.hasUpdate) {
						updateManager.onUpdateReady(function(ress) {
							updateManager.applyUpdate()
						})
					} else {
						uni.showToast({
							title: '已更新至最新版本',
							icon: "none"
						})
					}
				})
			},
			biaji() {
				if (this.token == '') {
					this.showxieyi = true
					return false
				}
				uni.navigateTo({
					url: '/pagesA/my_user_information/my_user_information'
				})
			},
			dianji() {
				this.checked = !this.checked
			},
			getUserInfo() {
				let that = this

				uni.getProvider({
					service: 'oauth',
					success: function(res) {
						if (~res.provider.indexOf('weixin')) {
							uni.showLoading({
								title: '正在授权'
							})
							wx.login({
								success: async (res) => {
									that.code = res.code
									uni.setStorageSync("code", res.code);

								}
							})

						} else {
							uni.showToast({
								title: '请先安装微信或升级版本',
								icon: "none"
							})
						}
					}
				})
			},
			// 手机号授权
			onGetPhoneNumber(e) {
				let that = this
				if (e.detail.errMsg == "getPhoneNumber:fail user deny") { //用户决绝授权  
					//拒绝授权后弹出一些提示  
				} else { //允许授权

					if (!this.checked) {
						uni.showToast({
							icon: "none",
							title: '请阅读并同意协议'
						})
						return false
					}
					var obj = {
						code: e.detail.code,
					}
					this.api.post('login/dologin', {
						code: e.detail.code,
						invite_id: uni.getStorageSync('invite_id') || ''
						// code:that.code
					}).then(res => {
						if (res.code == 200) {
							that.token = res.data.token
							uni.setStorageSync("token", res.data.token);
							uni.showToast({
								icon: "none",
								title: '登录成功'
							})
							that.getuser()
							setTimeout(function() {
								that.showxieyi = false
							}, 1000)
						}


					})
				}
			},

			getuser() {
				let that = this
				this.api.post('user/getUsermsg').then(res => {
					if (res.code == 200) {
						this.userInfo = res.data
						uni.setStorageSync("userInfo", res.data);
					} else {
						this.userInfo = res.data
					}
				})
			},
			yopngh(index) {

				if (index == 1) {
					uni.navigateTo({
						url: '/pagesA/in_text/in_text?type=' + 5
					})
				}
				if (index == 2) {
					uni.navigateTo({
						url: '/pagesA/in_text/in_text?type=' + 6
					})
				}
			},
			jump(url) {
				if (this.token == '') {
					this.showxieyi = true
					return false
				}
				uni.navigateTo({
					url: url
				})
			},
			close() {
				this.showxieyi = false
			},
		}
	}
</script>

<style>
	.icon-tuiguangma {
		color: #feb746;
		font-size: 56rpx;
	}

	.icon-shiyongshuoming {
		color: #feb746;
		font-size: 52rpx;
	}

	.icon-kefu {
		color: #feb746;
		font-size: 52rpx;
	}

	.icon-tuandui {
		color: #feb746;
		font-size: 52rpx;
	}

	.icon-xiaofeimingxidan {
		color: #52d0ff;
		font-size: 52rpx;
	}

	.icon-jifen {
		color: #52d0ff;
		font-size: 52rpx;
	}

	.icon-tixian {
		color: #52d0ff;
		font-size: 52rpx;
	}

	.mian {
		background-color: #fff;
		border-radius: 10rpx;
		width: 92%;
		margin-left: 30rpx;
		margin-top: 20rpx;
		padding: 25rpx;
		box-sizing: border-box;
	}

	.icon-ziliao {
		color: #52d0ff;
		font-size: 56rpx;
	}

	.icon-store {
		color: #feb746;
		font-size: 56rpx;
	}

	.icon-a-quanbu2 {
		color: #feb746;
		font-size: 56rpx;
	}

	.icon-yiwancheng2 {
		color: #feb746;
		font-size: 56rpx;
	}

	.icon-daifahuo {
		color: #feb746;
		font-size: 56rpx;
	}

	.yue {
		background-color: #feb746;
		border-radius: 10rpx;
		height: 80rpx;
		width: 92%;
		margin-left: 30rpx;
		margin-top: 20rpx;
		color: #fff;
		font-size: 26rpx;
	}

	.shangj {
		background-color: #31312d;
		padding: 5rpx 13rpx;
		font-size: 24rpx;
		border-radius: 30rpx;
		color: #f2dcac;
	}

	.topmxx {
		background-color: #feb746;
		padding: 25rpx;
	}

	button::after {
		border: none;
		padding: 0 !important;
	}

	button {
		padding: 0 !important;

	}

	.icon-weixin {
		font-size: 70rpx;
		padding-right: 15rpx;
	}

	.wxbtn {
		width: 600rpx;
		height: 120rpx;
		background-color: #feb746 !important;
		border-radius: 16rpx;
	}

	.login_box {
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		width: 100%;
		height: 100%;
	}

	.baoqu {
		width: 100%;
		height: 100%;
	}

	.puop {
		position: absolute;
		width: 750rpx;
		height: 545rpx;
		bottom: 0;
		z-index: 9;
	}

	.maxxback {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: flex-end;
		background-color: rgba(0, 0, 0, 0.7);
	}

	.mxxsubmit {
		width: 80rpx;
		height: 80rpx;
	}

	.mxxaccess {
		position: relative;
		width: 92%;
		margin-left: 30rpx;
		height: 150rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 0 25rpx;
	}

	.xian {
		width: 2rpx;
		height: 101rpx;
		background-color: #E3E3E3;
	}

	.mengyimg {
		width: 89rpx;
		height: 34rpx;
	}

	.icon-xiangyoujiantou {
		color: #ACACAC;
		font-size: 28rpx;
	}

	.iconmxx {
		width: 60rpx;
		height: 56rpx;
	}

	.speciesmxx {
		width: 92%;
		height: 170rpx;
		margin-left: 30rpx;
		margin-top: 10rpx;
	}

	.species {
		width: 92%;
		height: 170rpx;
		margin-left: 30rpx;
	}

	.icon-bianji {

		font-size: 26rpx;
		padding-left: 15rpx;
	}

	.userimg {
		width: 136rpx;
		height: 136rpx;
		border-radius: 160rpx;
	}
</style>